package com.sinosun.autotestmachine.tools.proxy;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.sinosun.autotestmachine.App;
import com.sinosun.autotestmachine.tools.ValueInfo;
import com.sinosun.autotestmachine.tools.ValueType;
import com.sinosun.autotestmachine.tools.Collector.Cache;
import com.sinosun.autotestmachine.tools.Collector.FileCancelCollector;
import com.sinosun.autotestmachine.tools.Collector.FileloadCollector;
import com.sinosun.autotestmachine.tools.parser.ContentMaker;
import com.sinosun.autotestmachine.tools.parser.FileDetail;
import com.sinosun.autotestmachine.tools.parser.FileInfoHolder;
import com.sinosun.autotestmachine.tools.parser.FileType;
import com.sinosun.autotestmachine.tools.parser.GroupHolder;
import com.sinosun.autotestmachine.tools.parser.NodeDetail;
import com.sinosun.autotestmachine.tools.parser.ParamKey;
import com.sinosun.autotestmachine.tools.parser.ShareInfoDetail;
import com.sinosun.autotestmachine.tools.proxy.callback.CallbackWrapper;
import com.sinosun.autotestmachine.tools.proxy.callback.FileloadInfo;
import com.sinosun.autotestmachine.tools.utils.Md5Util;
import com.sinosun.autotestmachine.tools.utils.MimeType;
import com.sinosun.autotestmachine.tools.utils.Utils;
import com.sinosun.mstplib.FilePolicy;
import com.sinosun.mstplib.MstpClient;
import com.sinosun.mstplib.MstpException;
import com.sinosun.mstplib.clouddisk.CategoryTag;
import com.sinosun.mstplib.clouddisk.ImagePolicy;
import com.sinosun.mstplib.clouddisk.NodeInfo;
import com.sinosun.mstplib.clouddisk.NodeType;
import com.sinosun.mstplib.clouddisk.ShareDetail;
import com.sinosun.mstplib.clouddisk.ShareInfo;
import com.sinosun.mstplib.clouddisk.ShareMode;
import com.sinosun.mstplib.clouddisk.UserType;
import com.sinosun.mstplib.clouddisk.VisibilityPolicy;

import android.text.TextUtils;
import android.util.Log;

public class CloudDiskModule {

	protected static int createCloudDiskAccount(MstpClient mstpClient) {
    	int ret = ErrorCode.SUCCESS;
    	try {
			mstpClient.getCloudDiskManager().createAccount();
		} catch (MstpException e) {
			e.printStackTrace();
			ret = e.getErrorCode();
		}
	    return ret;
	}
	
	protected static int tearDownCloudDiskEnv(MstpClient mstpClient) {
		List<NodeInfo> allNodes;
		try {
			mstpClient.getCloudDiskManager().createAccount();
			allNodes = mstpClient.getCloudDiskManager().queryFolderSubNodesInfo(mstpClient.getMstpId(), "0");
			List<String> allNodeStr = new ArrayList<String>();
			for (NodeInfo ele:allNodes) {
				allNodeStr.add(ele.getNodeId());
			}
			
			if (!(allNodeStr == null || allNodeStr.size() == 0)) {
				mstpClient.getCloudDiskManager().deleteNodes(mstpClient.getMstpId(), allNodeStr);
			}
		} catch (MstpException e) {
			e.printStackTrace();
//			return e.getErrorCode();
		}
		return ErrorCode.SUCCESS;
	}
	
	protected static int createCloudDiskFolder(MstpClient mstpClient, String paramJson, String cacheJson) {
		String parentFolderId = new String("");
		String nodeName = new String("");
		String cacheId = new String("");
		
		try {
			JSONObject jo = new JSONObject(paramJson);
			if (jo.has(ParamKey.PARENT_FOLDER_ID)) {
				parentFolderId = jo.getString(ParamKey.PARENT_FOLDER_ID);
				ValueInfo vi = Utils.getNodeIDRealInfo(parentFolderId);
				if (vi.getValueType() == ValueType.INDEX) {
					parentFolderId = Cache.allNodeId.get(parentFolderId).getNodeId();
				}
			} else {
				return ErrorCode.ERR_PARAM_ERROR;
			}
			if (jo.has(ParamKey.NODE_NAME)) {
				nodeName = jo.getString(ParamKey.NODE_NAME);
			} else {
				return ErrorCode.ERR_PARAM_ERROR;
			}
			if (cacheJson != null) {
				JSONObject cacheJo = new JSONObject(cacheJson);
				if (cacheJo.has(ParamKey.NODE_ID)) {
					cacheId = cacheJo.getString(ParamKey.NODE_ID);
				} else {
					return ErrorCode.ERR_PARAM_ERROR;
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
			return ErrorCode.ERR_PARAM_ERROR;
		}
		
		if (TextUtils.isEmpty(parentFolderId)) {
			return ErrorCode.ERR_PARAM_ERROR;
		}
		
		String nodeId = new String("");
		int ret = ErrorCode.SUCCESS;
		try {
			nodeId = mstpClient.getCloudDiskManager().createFolder(mstpClient.getMstpId(), parentFolderId, nodeName);
			
			List<NodeInfo> nodesInfo = mstpClient.getCloudDiskManager().queryFolderSubNodesInfo(mstpClient.getMstpId(), parentFolderId);
			boolean createFlag = false;
			for (NodeInfo ele : nodesInfo) {
				if (ele.getNodeId().equals(nodeId) && ele.getName().contains(nodeName)) {
					createFlag = true;
					break;
				}
			}
			if (!createFlag) {
				ret = ErrorCode.ERR_UNEXPECT_RESULT;
			}
			if (!TextUtils.isEmpty(cacheId)) {
				NodeDetail nd = new NodeDetail();
				nd.setNodeId(nodeId);
				nd.setNodeName(nodeName);
				Cache.allNodeId.put(cacheId, nd);
			}
		} catch (MstpException e) {
			e.printStackTrace();
			ret = e.getErrorCode();
		}
		return ret;
	}
	
	protected static int createDuplicateCloudDiskFolder(MstpClient mstpClient, String paramJson) {
		int ret = ErrorCode.SUCCESS;
		ret = createCloudDiskFolder(mstpClient, paramJson, null);
		if (ret != ErrorCode.SUCCESS) {
			return ret;
		}
		return createCloudDiskFolder(mstpClient, paramJson, null);
	}
	
	
	protected static int uploadFileToCloudDisk(MstpClient mstpClient, String paramJson, String cacheJson) {
		List<String> caches = new ArrayList<String>();
		List<String> fileContentIds = new ArrayList<String>();
		String parentFolderId = new String("");
    	try {
			JSONObject jo = new JSONObject(paramJson);
			
			if (jo.has(ParamKey.FILE_CONTENT_ID)) {
				JSONArray ja = jo.getJSONArray(ParamKey.FILE_CONTENT_ID);
				for (int i = 0; i < ja.length(); i++) {
					String tmp = ja.getString(i);
					ValueInfo vi = Utils.getMsgRealInfo(tmp);
					if (vi.getValueType() == ValueType.INDEX) {
						tmp = App.getTestConfig().getFileContent().get(vi.getValueContent());
					} else {
						tmp = vi.getValueContent();
					}
					Log.e("XXX", "uploadFileToCloudDisk tmp " + tmp);
					fileContentIds.add(tmp);
				}
			} else {
				return ErrorCode.ERR_PARAM_ERROR;
			}
			if (jo.has(ParamKey.PARENT_FOLDER_ID)) {
				String tmp = jo.getString(ParamKey.PARENT_FOLDER_ID);
				ValueInfo vi = Utils.getNodeIDRealInfo(tmp);
				if (vi.getValueType() == ValueType.INDEX) {
					tmp = Cache.allNodeId.get(tmp).getNodeId();
				}
				parentFolderId = tmp;
			} else {
				return ErrorCode.ERR_PARAM_ERROR;
			}
			
			if (cacheJson != null) {
				JSONObject cachesJo = new JSONObject(cacheJson);
				if (cachesJo.has(ParamKey.NODE_ID)) {
					JSONArray ja = cachesJo.getJSONArray(ParamKey.NODE_ID);
					for (int i = 0; i < ja.length(); i++) {
						caches.add(ja.getString(i));
					}
				} else {
					return ErrorCode.ERR_PARAM_ERROR;
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
			return ErrorCode.ERR_PARAM_ERROR;
		}
    	
    	if (fileContentIds.size() <= 0 || TextUtils.isEmpty(parentFolderId)) {
			return ErrorCode.ERR_PARAM_ERROR;
		}	
    	
    	FileloadCollector collector = new FileloadCollector();
    	List<FileDetail> allFile = new ArrayList<FileDetail>();
    	for (String fileContentId : fileContentIds) {
    		Log.e("XXX", "uploadFileToCloudDisk > fileContentId=" + fileContentId);
    		FileInfoHolder get = ContentMaker.getFileInfoHolder(fileContentId);
    		if (get == null) {
    			return ErrorCode.ERR_PARAM_ERROR;
    		}
    		if (get.getFilesize() < 0) {
    			return ErrorCode.ERR_PARAM_ERROR;
    		}
    		
    		String filePath = new String();
    		String name = get.getFileName();
    		
    		if (get.getFileType() == FileType.FILE.value()) {
    			name = ContentMaker.generateSizedFile(App.getInstance().getUploadPath(), (int)get.getFilesize(), name);
    		} else if (get.getFileType() == FileType.IMAGE.value()) {
    			name = ContentMaker.generateImageFile(App.getInstance().getUploadPath(), name);
    		} else if (get.getFileType() == FileType.AUDIO.value()) {
    			name = ContentMaker.generateSizedAudioFile(App.getInstance().getUploadPath(), (int)get.getFilesize(), name);
    		} else if (get.getFileType() == FileType.VIDEO.value()) {
    			name = ContentMaker.generateSizedVideoFile(App.getInstance().getUploadPath(), (int)get.getFilesize(), name);
    		} else {
    			return ErrorCode.ERR_PARAM_ERROR;
    		}
    		filePath = App.getInstance().getUploadPath() + name;
    		String actionId;
    		FileDetail item = new FileDetail();
			item.setMD5(Md5Util.getFileMD5(filePath));
			item.setFileType(FileType.valueOf(get.getFileType()));
			item.setFileName(name);
			item.setInCache(true);
			allFile.add(item);
			try {
				Log.e("XXX", "uploadFileToCloudDisk parentFolderId -> " + parentFolderId);
				Log.e("XXX", "uploadFileToCloudDisk filePath -> " + filePath);
				Log.e("XXX", "uploadFileToCloudDisk mimeType -> " + MimeType.getMimeType(filePath));
				actionId = mstpClient.getCloudDiskManager().uploadFile(mstpClient.getMstpId(), parentFolderId, filePath, MimeType.getMimeType(filePath), null, false);
				FileloadInfo ele = new FileloadInfo();
				ele.setTrasactionId(actionId);
				collector.addFileID(ele);
			} catch (MstpException e) {
				e.printStackTrace();
				return e.getErrorCode();
			}
    	}
    	
		CallbackWrapper.makeCloudDiskCallback(collector, true);
		try {
			collector.waitResult();
		} catch (InterruptedException e) {
			e.printStackTrace();
			return ErrorCode.ERR_UNEXPECT_RESULT;
		}
		CallbackWrapper.clearCloudDiskCallback();
//		if (collector.getResult() == ErrorCode.SUCCESS) {
			Log.e("XXX", "caches.size() = " + caches.size());
			for (int i = 0; i < caches.size(); i++) {
				allFile.get(i).setFileId(collector.getFileInfos().get(i).getFileId());
				Log.e("XXX", "uploadFileToCloudDisk fileId=" + allFile.get(i).getFileId());
				Cache.allUploadFile.put(caches.get(i), allFile.get(i));
				NodeDetail node = new NodeDetail();
				node.setNodeId(allFile.get(i).getFileId());
				node.setNodeName(allFile.get(i).getFileName());
				Cache.allNodeId.put(caches.get(i), node);
			}
//		}
    	return collector.getResult();
	}
	
	protected static int downloadCloudDiskFile(MstpClient mstpClient, String paramJson) {
		Log.e("XXX", "downloadCloudDiskFile start");
		List<FileDetail> fileIds = new ArrayList<FileDetail>();
		try {
			JSONObject jo = new JSONObject(paramJson);
			if (jo.has(ParamKey.NODE_ID)) {
				JSONArray ja = jo.getJSONArray(ParamKey.NODE_ID);
				for (int i = 0; i < ja.length(); i++) {
					String tmp = ja.getString(i);
					ValueInfo vi = Utils.getFileIDRealInfo(tmp);
					if (vi.getValueType() == ValueType.INDEX) {
						FileDetail fd = Cache.allUploadFile.get(tmp);
						if (fd != null) {		//尝试从上传的目录检索
							fileIds.add(fd);
						} else {			//尝试从创建文件夹的节点查找
							NodeDetail nd = Cache.allNodeId.get(tmp);
							if (nd != null) {
								fd = new FileDetail();
								fd.setFileId(nd.getNodeId());
								fd.setInCache(false);
								fileIds.add(fd);
							}
						}
					} else {
						FileDetail fd = new FileDetail();
						fd.setFileId(tmp);
						fd.setInCache(false);
						fileIds.add(fd);
					}
				}
			} else {
				return ErrorCode.ERR_PARAM_ERROR;
			}
		} catch (JSONException e) {
			e.printStackTrace();
			return ErrorCode.ERR_PARAM_ERROR;
		}
		
		if (fileIds.size() <= 0) {
			return ErrorCode.ERR_PARAM_ERROR;
		}
		
		FileloadCollector collector = new FileloadCollector();
		List<FileDetail> downLoadFiles = new ArrayList<FileDetail>();
		for (FileDetail fileId : fileIds) {
			String path = App.getInstance().getDownloadPath() + System.currentTimeMillis();
			Log.e("XXX", "path = " + path);
			File file = new File(path);
			if (fileId.getInCache()) {
				FileDetail cpItem = new FileDetail();
				cpItem.setFileId(fileId.getFileId());
				cpItem.setMD5(path);
				downLoadFiles.add(cpItem);
			}
			try {
				Log.e("XXX", "downloadCloudDiskFile fileId=" + fileId.getFileId());
				Log.e("XXX", "downloadCloudDiskFile path=" + path);
				
				String transactionId = mstpClient.getCloudDiskManager().downloadFile(mstpClient.getMstpId(), fileId.getFileId(), path, null);
				FileloadInfo ele = new FileloadInfo();
				ele.setTrasactionId(transactionId);
				collector.addFileID(ele);
			} catch (MstpException e) {
				e.printStackTrace();
				return e.getErrorCode();
			}
		}
		CallbackWrapper.makeCloudDiskCallback(collector, false);
		try {
			collector.waitResult();
		} catch (InterruptedException e) {
			e.printStackTrace();
			return ErrorCode.ERR_UNEXPECT_RESULT;
		}
		if (collector.getResult() != ErrorCode.SUCCESS) {
			return collector.getResult();
		}
		
		List<FileDetail> tagMap = new ArrayList<FileDetail>();
		for (FileDetail tmpFd : Cache.allUploadFile.values()) {
			FileDetail tagItem = new FileDetail();
			tagItem.setFileId(tmpFd.getFileId());
			tagItem.setMD5(tmpFd.getMD5());
			tagMap.add(tagItem);
		}
		
		for (int i = 0; i < downLoadFiles.size(); i++) {
			downLoadFiles.get(i).setMD5(Md5Util.getFileMD5(downLoadFiles.get(i).getMD5()));
			Log.e("XXX", "tag fileId=" + downLoadFiles.get(i).getFileId());
			Log.e("XXX", "tag md5=" + downLoadFiles.get(i).getMD5());
		}
		if (tagMap.containsAll(downLoadFiles)) {
			return ErrorCode.SUCCESS;
		} else {
			return ErrorCode.ERR_UNEXPECT_RESULT;
		}
	}
	
	protected static int cancelUploadFileToCloudDisk(MstpClient mstpClient, String paramJson) {
		List<String> allFileContent = new ArrayList<String>();
		int cancelPoint = 0;
		String parentFolderId = new String("");
		try {
			JSONObject jo = new JSONObject(paramJson);
			if (jo.has(ParamKey.FILE_CONTENT_ID)) {
				
				JSONArray ja = jo.getJSONArray(ParamKey.FILE_CONTENT_ID);
				for (int i = 0; i < ja.length(); i++) {
					String tmp = ja.getString(i);
					ValueInfo vi = Utils.getMsgRealInfo(tmp);
					if (vi.getValueType() == ValueType.INDEX) {
						tmp = App.getTestConfig().getFileContent().get(vi.getValueContent());
					}
					allFileContent.add(tmp);
				}
				
			} else {
				return ErrorCode.ERR_PARAM_ERROR;
			}
			
			if (jo.has(ParamKey.PARENT_FOLDER_ID)) {
				String tmp = jo.getString(ParamKey.PARENT_FOLDER_ID);
				ValueInfo vi = Utils.getNodeIDRealInfo(tmp);
				if (vi.getValueType() == ValueType.INDEX) {
					tmp = Cache.allNodeId.get(tmp).getNodeId();
				}
				parentFolderId = tmp;
			} else {
				return ErrorCode.ERR_PARAM_ERROR;
			}
			
			if (jo.has(ParamKey.CANCEL_POINT)) {
				cancelPoint = jo.getInt(ParamKey.CANCEL_POINT);
			} else {
				return ErrorCode.ERR_PARAM_ERROR;
			}
		} catch (JSONException e) {
			e.printStackTrace();
			return ErrorCode.ERR_PARAM_ERROR;
		}
		
		FileCancelCollector collector = new FileCancelCollector();
		collector.setCancelPoint(cancelPoint);
		
		for (String fileContentId : allFileContent) {
			FileInfoHolder get = ContentMaker.getFileInfoHolder(fileContentId);
			if (get == null || get.getFilesize() <= 0) {
				return ErrorCode.ERR_PARAM_ERROR;
			}
				
			FilePolicy policy = new FilePolicy();
			String name = get.getFileName();
			if (get.getFileType() == FileType.FILE.value()) {
				name = ContentMaker.generateSizedFile(App.getInstance().getUploadPath(), (int) get.getFilesize(), name);
			} else if (get.getFileType() == FileType.IMAGE.value()) {
				name = ContentMaker.generateImageFile(App.getInstance().getUploadPath(), name);
				if (!TextUtils.isEmpty(get.getImagePolicy())) {
					ImagePolicy ip = new ImagePolicy();
					policy.setImagePolicy(ip.toString());
				}
			} else if (get.getFileType() == FileType.AUDIO.value()) {
				name = ContentMaker.generateSizedAudioFile(App.getInstance().getUploadPath(), (int)get.getFilesize(), name);
			} else if (get.getFileType() == FileType.VIDEO.value()) {
				name = ContentMaker.generateSizedVideoFile(App.getInstance().getUploadPath(), (int)get.getFilesize(), name);
			} else {
				return ErrorCode.ERR_PARAM_ERROR;
			}
			policy.setEncrypt(get.getEncrypt() != 0);
			String filePath = new String();
			filePath = App.getInstance().getUploadPath() + name;
			
			try {
				String actionId = mstpClient.getCloudDiskManager().uploadFile(mstpClient.getMstpId(), parentFolderId, filePath, MimeType.getMimeType(filePath), null, false);
				collector.putTrasactionId(actionId, false);
				
			} catch (MstpException e) {
				e.printStackTrace();
				return e.getErrorCode();
			}
		}
		
		CallbackWrapper.makeCancelCloudDiskCallback(mstpClient, collector, true);
		
		try {
			collector.waitResult();
		} catch (InterruptedException e) {
			e.printStackTrace();
			return ErrorCode.ERR_UNEXPECT_RESULT;
		}
	
		return collector.getResult();
	}
	
	protected static int cancelDownloadCloudDiskFile(MstpClient mstpClient, String paramJson) {
		List<String> allFileId = new ArrayList<String>();
		int cancelPoint = 0;
		try {
			JSONObject jo = new JSONObject(paramJson);
			if (jo.has(ParamKey.NODE_ID)) {
				JSONArray ja = jo.getJSONArray(ParamKey.NODE_ID);
				for (int i = 0; i < ja.length(); i++) {
					String fileId = ja.getString(i);
					Log.e("XXX", "fileId - " + fileId);
					ValueInfo vi = Utils.getNodeIDRealInfo(fileId);
					
					if (vi.getValueType() == ValueType.INDEX) {
						fileId = Cache.allUploadFile.get(fileId).getFileId();
					}
					allFileId.add(fileId);
				}
			} else {
				return ErrorCode.ERR_PARAM_ERROR;
			}
			
			if (jo.has(ParamKey.CANCEL_POINT)) {
				cancelPoint = jo.getInt(ParamKey.CANCEL_POINT);
			} else {
				return ErrorCode.ERR_PARAM_ERROR;
			}
		} catch (JSONException e) {
			e.printStackTrace();
			return ErrorCode.ERR_PARAM_ERROR;
		}
		
		try {
			FileCancelCollector collector = new FileCancelCollector();
			collector.setCancelPoint(cancelPoint);
			for (String itemFileId : allFileId) {
				Log.e("XXX", "cancelDownloadCloudDiskFile fielId=" + itemFileId);
				String transactionId = mstpClient.getCloudDiskManager().downloadFile(mstpClient.getMstpId(), itemFileId, App.getInstance().getDownloadPath() + ContentMaker.random(9), null);
				collector.putTrasactionId(transactionId, false);
			}
			CallbackWrapper.makeCancelCloudDiskCallback(mstpClient, collector, false);
			collector.waitResult();
			return collector.getResult();
		} catch (MstpException e) {
			e.printStackTrace();
			return e.getErrorCode();
		} catch (InterruptedException e) {
			e.printStackTrace();
			return ErrorCode.ERR_UNEXPECT_RESULT;
		}
	}
	
	protected static int cloudDiskBrowseByCategory(MstpClient mstpClient, String paramJson) {
		List<String> nodeIds = new ArrayList<String>();
		int type = -1;
		
		try {
			JSONObject jo = new JSONObject(paramJson);
			if (jo.has(ParamKey.FILE_TYPE)) {
				type = jo.getInt(ParamKey.FILE_TYPE);
			} else {
				return ErrorCode.ERR_PARAM_ERROR;
			}
			
			if (jo.has(ParamKey.NODE_ID)) {
				JSONArray ja = jo.getJSONArray(ParamKey.NODE_ID);
				for (int i = 0; i < ja.length(); i++) {
					String tmp = ja.getString(i);
					ValueInfo vi = Utils.getNodeIDRealInfo(tmp);
					if (vi.getValueType() == ValueType.INDEX) {
						tmp = Cache.allUploadFile.get(tmp).getFileId();
					}
					Log.e("XXX", "cloudDiskBrowseByCategory node is " + tmp);
					nodeIds.add(tmp);
				}
			} else {
				return ErrorCode.ERR_PARAM_ERROR;
			}
		} catch (JSONException e) {
			e.printStackTrace();
			return ErrorCode.ERR_PARAM_ERROR;
		}
		
		if (nodeIds.size() <= 0 && type == -1) {
			return ErrorCode.ERR_PARAM_ERROR;
		}
		
    	CategoryTag tag = null;
    	FileType tagFile = FileType.valueOf(type);
    	switch(tagFile) {
    	case FILE:
    		tag = CategoryTag.OTHER;
    		break;
    	case IMAGE:
    		tag = CategoryTag.IMAGE; 
    		break;
    	case AUDIO:
    		tag = CategoryTag.AUDIO;
    		break;
    	case VIDEO:
    		tag = CategoryTag.VIDEO;
    		break;
    	default:
    		tag = CategoryTag.OTHER;
    		break;
    	}
    	try {
			List<NodeInfo> allNodes = mstpClient.getCloudDiskManager().browseByCategory(mstpClient.getMstpId(), tag);
			List<String> tagNodes = new ArrayList<String>();
			for(NodeInfo node : allNodes) {
				tagNodes.add(node.getNodeId());
				Log.e("XXX", "cloudDiskBrowseByCategory tag node = " + node.getNodeId());
			}
			
			if (tagNodes.containsAll(nodeIds)) {
				return ErrorCode.SUCCESS;
			} else {
				return ErrorCode.ERR_BROWSER_CATEGORY_ERROR;
			}
		} catch (MstpException e) {
			e.printStackTrace();
			return e.getErrorCode();
		}
	}
	
	protected static int moveCloudDiskNode(MstpClient mstpClient, String paramJson, String cacheJson) {
		List<String> srcNodeIds = new ArrayList<String>();
		String destNodeId = new String("");
		List<String> cahceNode = new ArrayList<String>();
		
		try {
			JSONObject jo = new JSONObject(paramJson);
			if (jo.has(ParamKey.SRC_NODE_ID)) {
				JSONArray ja = jo.getJSONArray(ParamKey.SRC_NODE_ID);
				for (int i = 0; i < ja.length(); i++) {
					String tmp = ja.getString(i);
					ValueInfo vi = Utils.getNodeIDRealInfo(tmp);
					if (vi.getValueType() == ValueType.INDEX) {
						tmp = Cache.allNodeId.get(tmp).getNodeId();
					}
					srcNodeIds.add(tmp);
				}
			} else {
				return ErrorCode.ERR_PARAM_ERROR;
			}
			
			if (jo.has(ParamKey.DEST_NODE_ID)) {
				destNodeId = jo.getString(ParamKey.DEST_NODE_ID);
				ValueInfo vi = Utils.getNodeIDRealInfo(destNodeId);
				if (vi.getValueType() == ValueType.INDEX) {
					destNodeId = Cache.allNodeId.get(destNodeId).getNodeId();
				}
			} else {
				return ErrorCode.ERR_PARAM_ERROR;
			}
			
			if (cacheJson != null) {
				JSONObject cacheJo = new JSONObject(cacheJson);
				if (cacheJo.has(ParamKey.AFTER_MOVE_NODEID)) {
					JSONArray cacheJa = cacheJo.getJSONArray(ParamKey.AFTER_MOVE_NODEID);
					for (int i = 0; i < cacheJa.length(); i++) {
						cahceNode.add(cacheJa.getString(i));
					}
				} else {
					return ErrorCode.ERR_PARAM_ERROR;
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
			return ErrorCode.ERR_PARAM_ERROR;
		}
		
		try {
			mstpClient.getCloudDiskManager().moveNodes(mstpClient.getMstpId(), srcNodeIds, destNodeId);
			List<NodeInfo> allNodes = mstpClient.getCloudDiskManager().queryFolderSubNodesInfo(mstpClient.getMstpId(), destNodeId);
			
			List<String> tagNodes = new ArrayList<String>();
    		for (NodeInfo ele : allNodes) {
    			tagNodes.add(ele.getNodeId());
    		}
    		
    		for (int i = 0; i < cahceNode.size(); i++) {
    			NodeDetail nd = new NodeDetail();
    			nd.setNodeId(srcNodeIds.get(i));
    			if (i < cahceNode.size()) {
    				Cache.allNodeId.put(cahceNode.get(i), nd);
    			}
    		}
    		
    		if (tagNodes.containsAll(srcNodeIds)) {
    			return ErrorCode.SUCCESS;
    		} else {
    			return ErrorCode.ERR_UNEXPECT_RESULT;
    		}
			
		} catch (MstpException e) {
			e.printStackTrace();
			return ErrorCode.ERR_UNEXPECT_RESULT;
		}
	}
	
	protected static int copyCloudDiskNode(MstpClient mstpClient, String paramJson, String cacheJson) {
		List<String> srcNodeIds = new ArrayList<String>();
		List<String> srcNodeName = new ArrayList<String>();
		String destNodeId = new String("");
		List<String> cahceNode = new ArrayList<String>();
		
		try {
			JSONObject jo = new JSONObject(paramJson);
			if (jo.has(ParamKey.SRC_NODE_ID)) {
				JSONArray ja = jo.getJSONArray(ParamKey.SRC_NODE_ID);
				for (int i = 0; i < ja.length(); i++) {
					String tmp = ja.getString(i);
					String name = new String("");
					ValueInfo vi = Utils.getNodeIDRealInfo(tmp);
					if (vi.getValueType() == ValueType.INDEX) {
						name = Cache.allNodeId.get(tmp).getNodeName();
						tmp = Cache.allNodeId.get(tmp).getNodeId();
						
					}
					srcNodeIds.add(tmp);
					srcNodeName.add(name);
				}
			} else {
				return ErrorCode.ERR_PARAM_ERROR;
			}
			
			if (jo.has(ParamKey.DEST_NODE_ID)) {
				destNodeId = jo.getString(ParamKey.DEST_NODE_ID);
				ValueInfo vi = Utils.getNodeIDRealInfo(destNodeId);
				if (vi.getValueType() == ValueType.INDEX) {
					destNodeId = Cache.allNodeId.get(destNodeId).getNodeId();
				}
			} else {
				return ErrorCode.ERR_PARAM_ERROR;
			}
			
			if (cacheJson != null) {
				JSONObject cacheJo = new JSONObject(cacheJson);
				if (cacheJo.has(ParamKey.AFTER_COPY_NODEID)) {
					JSONArray cacheJa = cacheJo.getJSONArray(ParamKey.AFTER_COPY_NODEID);
					for (int i = 0; i < cacheJa.length(); i++) {
						cahceNode.add(cacheJa.getString(i));
					}
				} else {
					return ErrorCode.ERR_PARAM_ERROR;
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
			return ErrorCode.ERR_PARAM_ERROR;
		}
		
		try {
			Log.e("XXX", "destNodeId -> " + destNodeId);
			Log.e("XXX", "srcNodeIds size -> " + srcNodeIds.size());
			
			mstpClient.getCloudDiskManager().copyNodes(mstpClient.getMstpId(), srcNodeIds, destNodeId);
			List<NodeInfo> allNodes = mstpClient.getCloudDiskManager().queryFolderSubNodesInfo(mstpClient.getMstpId(), destNodeId);
			
			List<String> tagNodes = new ArrayList<String>();
    		for (NodeInfo ele : allNodes) {
    			tagNodes.add(ele.getName());
    		}
    		
    		for (String item : srcNodeIds) {
    			if (TextUtils.isEmpty(getParentNode(mstpClient, item))) {
    				return ErrorCode.ERR_UNEXPECT_RESULT;
    			}
    		}
    		int compareFlag = 0;
    		for (int i = 0; i < tagNodes.size(); i++) {
    			for (int j = 0; j < srcNodeName.size(); j++) {
    				if (tagNodes.get(i).equals(srcNodeName.get(j))) {
    					
    					NodeDetail nd = new NodeDetail();
    	    			nd.setNodeId(allNodes.get(i).getNodeId());
    	    			nd.setNodeName(allNodes.get(i).getName());
    	    			if (j < cahceNode.size()) {
    	    				Cache.allNodeId.put(cahceNode.get(j), nd);
    	    			}
    					compareFlag++;
    					break;
    				}
    			}
    		}
    		if (compareFlag == srcNodeName.size()) {
    			return ErrorCode.SUCCESS;
    		} else {
    			return ErrorCode.ERR_UNEXPECT_RESULT;
    		}
			
		} catch (MstpException e) {
			e.printStackTrace();
			return e.getErrorCode();
		}
	}
	
	protected static String getParentNode(MstpClient mstpCient, String node) {
		try {
			List<NodeInfo> allNodes = mstpCient.getCloudDiskManager().queryFolderSubNodesInfo(mstpCient.getMstpId(), "0");		//从父节点开始查询
			for (NodeInfo ele : allNodes) {
				if (ele.getNodeId().equals(node)) {		//查到指定节点返回父节点
					return "0";
				} else {
					if (ele.getNodeType() == NodeType.FOLDER) {		//查到的子节点是个文件夹
						String get = getNodeParent(mstpCient, ele.getNodeId(), node);
						if (!TextUtils.isEmpty(get)) {		//查到结果，直接跳出
							return get;
						}
					}
				}
			}
		} catch (MstpException e) {
			e.printStackTrace();
			return null;
		}
		return null;		//不存在对应节点的父节点
	}
	
	private static String getNodeParent(MstpClient mstpCient, String parentNode, String node) {		//返回父节点以下节点的父节点
		try {
			List<NodeInfo> allNodes = mstpCient.getCloudDiskManager().queryFolderSubNodesInfo(mstpCient.getMstpId(), parentNode);
			for (NodeInfo ele : allNodes) {
				if (ele.getNodeId().equals(node)) {
					return parentNode;
				} else {
					if (ele.getNodeType() == NodeType.FOLDER) {
						String get = getNodeParent(mstpCient, ele.getNodeId(), node);
						if (!TextUtils.isEmpty(get)) {
							return get;
						}
					}
				}
			}
		} catch (MstpException e) {
			e.printStackTrace();
			return null;
		}
		return null;
	}
	
	protected static int deleteCloudDiskNode(MstpClient mstpClient, String paramJson) {
		List<String> deletNodes = new ArrayList<String>();
		try {
			JSONObject jo = new JSONObject(paramJson);
			if (jo.has(ParamKey.NODE_ID)) {
				JSONArray ja = jo.getJSONArray(ParamKey.NODE_ID);
				for (int i = 0; i < ja.length(); i++) {
					String tmp = ja.getString(i);
					ValueInfo vi = Utils.getNodeIDRealInfo(tmp);
					if (vi.getValueType() == ValueType.INDEX) {
						tmp = Cache.allNodeId.get(tmp).getNodeId();
					}
					deletNodes.add(tmp);
				}
			} else {
				return ErrorCode.ERR_PARAM_ERROR;
			}
		} catch (JSONException e) {
			e.printStackTrace();
			return ErrorCode.ERR_PARAM_ERROR;
		}
		
		try {
			mstpClient.getCloudDiskManager().deleteNodes(mstpClient.getMstpId(), deletNodes);
			for (String item : deletNodes) {
				if (!TextUtils.isEmpty(getParentNode(mstpClient, item))) {
					return ErrorCode.ERR_UNEXPECT_RESULT;
				}
			}
		} catch (MstpException e) {
			e.printStackTrace();
			return e.getErrorCode();
		}
		
		return ErrorCode.SUCCESS;
	}
	
	protected static int renameCloudDiskNode(MstpClient mstpClient, String paramJson) {
		String nodeID = new String("");
		String newName = new String("");
		try {
			JSONObject jo = new JSONObject(paramJson);
			if (jo.has(ParamKey.RENAME_NODEID)) {
				nodeID = jo.getString(ParamKey.RENAME_NODEID);
				ValueInfo vi = Utils.getNodeIDRealInfo(nodeID);
				if (vi.getValueType() == ValueType.INDEX) {
					nodeID = Cache.allNodeId.get(nodeID).getNodeId();
				}
			} else {
				return ErrorCode.ERR_PARAM_ERROR;
			}
			
			if (jo.has(ParamKey.NEW_NAME)) {
				newName = jo.getString(ParamKey.NEW_NAME);
			} else {
				return ErrorCode.ERR_PARAM_ERROR;
			}
		} catch (JSONException e) {
			e.printStackTrace();
			return ErrorCode.ERR_PARAM_ERROR;
		}
		
		try {
			mstpClient.getCloudDiskManager().renameFile(mstpClient.getMstpId(), nodeID, newName);
			String parentNode = getParentNode(mstpClient, nodeID);
			List<NodeInfo> allNodes = mstpClient.getCloudDiskManager().queryFolderSubNodesInfo(mstpClient.getMstpId(), parentNode);
			for (NodeInfo item : allNodes) {
				if (item.getNodeId().equals(nodeID) && item.getName().contains(newName)) {
					return ErrorCode.SUCCESS;
				}
			}
		} catch (MstpException e) {
			e.printStackTrace();
			return e.getErrorCode();
		}
		return ErrorCode.ERR_UNEXPECT_RESULT;
	}
	
	protected static int shareCloudDiskNode(MstpClient mstpClient, String paramJson, String cacheJson) {
		List<String> shareNodes = new ArrayList<String>();
		int vpInt = -1;
		String destMstpId = new String("");
		String cacheInfo = new String("");
		UserType userType = UserType.USER;
		int shareType = -1;
		try {
			JSONObject paramJo = new JSONObject(paramJson);
			if (paramJo.has(ParamKey.SHARE_NODE_LIST)) {
				JSONArray ja = paramJo.getJSONArray(ParamKey.SHARE_NODE_LIST);
				for (int i = 0; i < ja.length(); i++) {
					String tmp = ja.getString(i);
					ValueInfo vi = Utils.getNodeIDRealInfo(tmp);
					if (vi.getValueType() == ValueType.INDEX) {
						tmp = Cache.allNodeId.get(tmp).getNodeId();
					}
					shareNodes.add(tmp);
				}
			} else {
				return ErrorCode.ERR_PARAM_ERROR;
			}
			
			if (paramJo.has(ParamKey.SHARE_TYPE)) {
				shareType = paramJo.getInt(ParamKey.SHARE_TYPE);
			} else {
				return ErrorCode.ERR_PARAM_ERROR;
			}
			
			if (paramJo.has(ParamKey.VISIBILITY_POLICY)) {
				vpInt = paramJo.getInt(ParamKey.VISIBILITY_POLICY);
				if (vpInt == 0) {
					vpInt = 1;
				} else if (vpInt == 1) {
					vpInt = 0;
				}
			} else {
				return ErrorCode.ERR_PARAM_ERROR;
			}
			
			if (paramJo.has(ParamKey.DEST_MSTPID)) {
				if (shareType == 2) {
					destMstpId = paramJo.getString(ParamKey.DEST_MSTPID);
					ValueInfo vi = Utils.getUserRealInfo(destMstpId);
					if (vi.getValueType() == ValueType.INDEX) {
						destMstpId = App.getTestConfig().getUsers().get(vi.getValueContent());
					}
					userType = UserType.USER;
				} else {
					destMstpId = paramJo.getString(ParamKey.DEST_MSTPID);
					ValueInfo vi = Utils.getGroupMstpInfo(destMstpId);
					if (vi.getValueType() == ValueType.INDEX) {
						destMstpId = Cache.groupInfoCache.get(destMstpId).getMstpId();
					}
					userType = UserType.GROUP;
				}
			} else {
				return ErrorCode.ERR_PARAM_ERROR;
			}
			
			if (shareNodes.size() <= 0 || vpInt == -1) {
				return ErrorCode.ERR_PARAM_ERROR;
			}
			
			if (cacheJson != null) {
				JSONObject cacheJo = new JSONObject(cacheJson);
				if (cacheJo.has(ParamKey.SHARED_INFO)) {
					cacheInfo = cacheJo.getString(ParamKey.SHARED_INFO);
				} else {
					return ErrorCode.ERR_PARAM_ERROR;
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
			return ErrorCode.SUCCESS;
		}

		int ret = ErrorCode.SUCCESS;
		try {
			VisibilityPolicy vp = VisibilityPolicy.valueOf(vpInt);
			ShareMode shareMode = new ShareMode(vp);
			shareMode.setDestMstpId(destMstpId);
			shareMode.setDestMstpIdType(userType);
			Log.e("XXX", "shareCloudDiskNode shareNodes " + shareNodes);
			Log.e("XXX", "shareCloudDiskNode shareMode " + shareMode.getVisibilityPolicy());
			Log.e("XXX", "shareCloudDiskNode destMstpId " + destMstpId);
			Log.e("XXX", "shareCloudDiskNode userType " + userType);
			ShareInfo si = mstpClient.getCloudDiskManager().shareNodes(mstpClient.getMstpId(), shareNodes, shareMode);
			if (si == null) {
				ret = ErrorCode.ERR_UNEXPECT_RESULT;
			} else {
				List<ShareDetail> querryRes = mstpClient.getCloudDiskManager().queryMyShareListInfo(mstpClient.getMstpId());
				if (!TextUtils.isEmpty(si.getSharedId())) {
					List<String> allShareIds = new ArrayList<String>();
					for (ShareDetail element : querryRes) {
						allShareIds.add(element.getShareId());
					}
					Log.e("XXX", "shareCloudDiskNode shared " + querryRes);
					if (!allShareIds.contains(si.getSharedId())) {
						ret = -1003;
					}
				} else {
					ret = ErrorCode.ERR_UNEXPECT_RESULT;
				}
			}
			
			if (!TextUtils.isEmpty(cacheInfo)) {
				ShareInfoDetail sid = new ShareInfoDetail();
				sid.setSharedInfo(si);
				sid.setNodeList(shareNodes);
				Cache.allSharedInfo.put(cacheInfo, sid);
			}
		} catch (MstpException e) {
			Log.e("XXX", "shareCloudDiskNode get MstpException");
			e.printStackTrace();
			ret = e.getErrorCode();
		}
		
		return ret;
	}
	
	protected static int unshareCloudDiskNode(MstpClient mstpClient, String paramJson) {
		ShareInfo shareInfo = null;
		List<String> nodeIds = new ArrayList<String>();
		try {
			JSONObject jo = new JSONObject(paramJson);
			if (jo.has(ParamKey.SHARED_INFO)) {
				if (!jo.isNull(ParamKey.SHARED_INFO)) {
					String tmp = jo.getString(ParamKey.SHARED_INFO);
					ValueInfo vi = Utils.getNodeIDRealInfo(tmp);
					if (vi.getValueType() == ValueType.INDEX) {
						shareInfo  = Cache.allSharedInfo.get(tmp).getShareInfo();
					} else {
						return ErrorCode.ERR_PARAM_ERROR;
					}
				} else {
					shareInfo = null;
				}
				
			} else {
				return ErrorCode.ERR_PARAM_ERROR;
			}
			
			if (shareInfo == null) {
				return ErrorCode.ERR_PARAM_ERROR;
			}
			
			if (jo.has(ParamKey.NODE_ID) && !jo.isNull(ParamKey.NODE_ID)) {
				JSONArray ja = jo.getJSONArray(ParamKey.NODE_ID);
				for (int i = 0; i < ja.length(); i++) {
					String tmp = ja.getString(i);
					ValueInfo vi = Utils.getNodeIDRealInfo(tmp);
					if (vi.getValueType() == ValueType.INDEX) {
						tmp = Cache.allNodeId.get(tmp).getNodeId();
					}
					nodeIds.add(tmp);
				}
			} else {
				nodeIds = null;
			}
		} catch (JSONException e) {
			e.printStackTrace();
			return ErrorCode.ERR_PARAM_ERROR;
		}
		
		try {
			mstpClient.getCloudDiskManager().unshare(mstpClient.getMstpId(), shareInfo == null ? null : shareInfo.getSharedId(), nodeIds);
		} catch (MstpException e) {
			e.printStackTrace();
			return e.getErrorCode();
		}
		
		try {
			List<NodeInfo> allNodes = mstpClient.getCloudDiskManager().querySharedNodesInfo(shareInfo);
			List<String> allNodeIds = new ArrayList<String>();
			for (NodeInfo item : allNodes) {
				allNodeIds.add(item.getNodeId());
			}
			for (String node : nodeIds) {
				if (allNodeIds.contains(node)) {
					return ErrorCode.ERR_UNSHARED_ERROR;
				}
			}
			
		} catch (MstpException e) {
			e.printStackTrace();
			if (e.getErrorCode() ==com.sinosun.mstplib.ErrorCode.ERR_CD_SHAREINFO_ERROR) {
				return ErrorCode.SUCCESS;
			}
			return e.getErrorCode();
		}
		
		return ErrorCode.SUCCESS;
	}
	
	protected static int batchUnshareCloudDiskNode(MstpClient mstpClient, String paramJson) {
		List<ShareInfo> shareInfos = null;
		List<String> allShareId = null;
		try {
			JSONObject jo = new JSONObject(paramJson);
			if (jo.has(ParamKey.SHARED_INFO)) {
				if (!jo.isNull(ParamKey.SHARED_INFO)) {
					JSONArray ja = jo.getJSONArray(ParamKey.SHARED_INFO);
					shareInfos = new ArrayList<ShareInfo>();
					for (int i = 0; i < ja.length(); i++) {
						String tmp = ja.getString(i);
						ShareInfo shareInfo = null;
						ValueInfo vi = Utils.getNodeIDRealInfo(tmp);
						if (vi.getValueType() == ValueType.INDEX) {
							shareInfo  = Cache.allSharedInfo.get(tmp).getShareInfo();
						} else {
							return ErrorCode.ERR_PARAM_ERROR;
						}
						shareInfos.add(shareInfo);
					}
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
			return ErrorCode.ERR_PARAM_ERROR;
		}
		if (shareInfos != null) {
			allShareId = new ArrayList<String>();
			for (ShareInfo item : shareInfos) {
				if (item != null) {
					allShareId.add(item.getSharedId());
				}
			}
		}
		try {
			mstpClient.getCloudDiskManager().massUnshare(mstpClient.getMstpId(), allShareId);
			
			List<ShareDetail> allDeatil = mstpClient.getCloudDiskManager().queryMyShareListInfo(mstpClient.getMstpId());		//	查询我的分享
			List<String> tagList = new ArrayList<String>();		//获取所有我的分享的 shareId
			for (ShareDetail ele : allDeatil) {
				tagList.add(ele.getShareId());
			}

			for (String tag : allShareId) {		//遍历被取消分享的 shareId
				if (tagList.contains(tag)) {	//有一个被删除的还存在，返回错误
					return ErrorCode.ERR_UNEXPECT_RESULT;
				}
			}
			
		} catch (MstpException e) {
			e.printStackTrace();
			return e.getErrorCode();
		}
		return ErrorCode.SUCCESS;
	}
	
	protected static int querySharedNodesInfo(MstpClient mstpClient, String paramJson) {
		ShareInfoDetail shareInfo = null;
		try {
			JSONObject jo = new JSONObject(paramJson);
			if (jo.has(ParamKey.SHARED_INFO)) {
				String key = jo.getString(ParamKey.SHARED_INFO);
				shareInfo = Cache.allSharedInfo.get(key);
				if (shareInfo == null) {
					return ErrorCode.ERR_PARAM_ERROR;
				}
			} else {
				return ErrorCode.ERR_PARAM_ERROR;
			}
		} catch (JSONException e) {
			e.printStackTrace();
			return ErrorCode.ERR_PARAM_ERROR;
		}
		
		try {
			List<NodeInfo> allNodes = mstpClient.getCloudDiskManager().querySharedNodesInfo(shareInfo == null ? null : shareInfo.getShareInfo());
			List<String> tmp = new ArrayList<String>();
			for (NodeInfo item : allNodes) {
				tmp.add(item.getNodeId());
			}
			
			if (tmp.size() == 0) {
				return ErrorCode.ERR_QUERY_SHARENODE_ERROR;
			}
			
			if (shareInfo.getNodeIds().containsAll(tmp)) {
				return ErrorCode.SUCCESS;
			} else {
				return ErrorCode.ERR_QUERY_SHARENODE_ERROR;
			}
		} catch (MstpException e) {
			e.printStackTrace();
			return e.getErrorCode();
		}
	}
	
	protected static int dumpCloudDiskNode(MstpClient mstpClient, String paramJson, String cacheJson) {
		List<String> srcNodeIdList = null;
		List<String> nodesName = new ArrayList<String>();
		List<String> cacheNode = new ArrayList<String>();
		ShareInfo sharedInfo = null;
		String destFolderNode = null;
		String diskId = null;
		try {
			JSONObject jo = new JSONObject(paramJson);
			if (jo.has(ParamKey.DEST_FOLDERID)) {
				destFolderNode = jo.getString(ParamKey.DEST_FOLDERID);
				ValueInfo vi = Utils.getNodeIDRealInfo(destFolderNode);
				if (vi.getValueType() == ValueType.INDEX) {
					destFolderNode = Cache.allNodeId.get(destFolderNode).getNodeId();
				}
			} else {
				return ErrorCode.ERR_PARAM_ERROR;
			}
			
			if (jo.has(ParamKey.SRC_NODE_LIST) && !jo.isNull(ParamKey.SRC_NODE_LIST)) {
				srcNodeIdList = new ArrayList<String>();
				JSONArray ja = jo.getJSONArray(ParamKey.SRC_NODE_LIST);
				for (int i = 0 ; i < ja.length(); i++) {
					String tmp = ja.getString(i);
					String name = new String("");
					ValueInfo value = Utils.getUserRealInfo(tmp);
					if (value.getValueType() == ValueType.INDEX) {		// value 数据内容符合匹配规则，从内存中取出对应的 mstpId
						name = Cache.allNodeId.get(tmp).getNodeName();
						tmp = Cache.allNodeId.get(tmp).getNodeId();
					}
					nodesName.add(name);
					srcNodeIdList.add(tmp);
				}
			}
			
			if (jo.has(ParamKey.SHARED_INFO)) {
				if (!jo.isNull(ParamKey.SHARED_INFO)) {
					String tmp = jo.getString(ParamKey.SHARED_INFO);
					ValueInfo vi = Utils.getNodeIDRealInfo(tmp);
					if (vi.getValueType() == ValueType.INDEX) {
						sharedInfo = Cache.allSharedInfo.get(tmp).getShareInfo();
					} else {
						return ErrorCode.ERR_PARAM_ERROR;
					}
				} else {
					sharedInfo = null;
				}
			} else {
				return ErrorCode.ERR_PARAM_ERROR;
			}
			
			if (cacheJson != null) {
				JSONObject cacheJo = new JSONObject(cacheJson);
				if (cacheJo.has(ParamKey.AFTER_DUMP_NODEID)) {
					JSONArray cacheJa = cacheJo.getJSONArray(ParamKey.AFTER_DUMP_NODEID);
					for (int i = 0; i < cacheJa.length(); i++) {
						cacheNode.add(cacheJa.getString(i));
					}
				}
			}
			
			if (jo.has(ParamKey.DEST_DISKID)) {
				if (!jo.isNull(ParamKey.DEST_DISKID)) {
					diskId = jo.getString(ParamKey.DEST_DISKID);
					if (jo.has(ParamKey.TYPE) && jo.getInt(ParamKey.TYPE) == 1) {
						if (diskId != null) {
							ValueInfo value = Utils.getUserRealInfo(diskId);
							if (value.getValueType() == ValueType.INDEX) {		// value 数据内容符合匹配规则，从内存中取出对应的 mstpId
								diskId = App.getTestConfig().getUsers().get(value.getValueContent());
							}
						}
					} else {
						if (diskId != null) {
							ValueInfo vi = Utils.getGroupMstpInfo(diskId);
							if (vi.getValueType() == ValueType.INDEX) {
								GroupHolder groupResult = Cache.groupInfoCache.get(diskId);
								diskId = groupResult.getMstpId();
							}
						}
					}
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
			return ErrorCode.ERR_PARAM_ERROR;
		}
		
		try {
			createCloudDiskAccount(mstpClient);
			if (srcNodeIdList == null || srcNodeIdList.size() == 0) {	//如果转存所有的节点，保存转存前所有节点的信息
				List<NodeInfo> allName = mstpClient.getCloudDiskManager().querySharedNodesInfo(sharedInfo);
				nodesName = new ArrayList<String>();
				for (NodeInfo ele : allName) {
					nodesName.add(ele.getName());
				}
			}
			
			Log.e("XXX", "diskId=" + diskId + ", srcNodeIdList=" + srcNodeIdList + ", destFolderNode=" + destFolderNode);
			List<NodeInfo> tagNodes = new ArrayList<NodeInfo>();
			if (diskId == null) {
				mstpClient.getCloudDiskManager().fileDump(mstpClient.getMstpId(), sharedInfo, srcNodeIdList, destFolderNode);
				tagNodes = mstpClient.getCloudDiskManager().queryFolderSubNodesInfo(mstpClient.getMstpId(), destFolderNode);
			} else {
				mstpClient.getCloudDiskManager().fileDump(diskId, sharedInfo, srcNodeIdList, destFolderNode);
				tagNodes = mstpClient.getCloudDiskManager().queryFolderSubNodesInfo(diskId, destFolderNode);
			}
			
			
			int tag = 0;
			for (int i = 0; i < nodesName.size(); i++) {
				String ele = nodesName.get(i);
				for(int j = 0; j < tagNodes.size(); j++) {
					NodeInfo item = tagNodes.get(j);
					Log.e("XXX", "dumpCloudDiskNode nodeId " + item.getNodeId());
					if (ele.equals(item.getName())) {
						NodeDetail nd = new NodeDetail();
						nd.setNodeId(item.getNodeId());
						nd.setNodeName(item.getName());
						if (i < cacheNode.size()) {
							Cache.allNodeId.put(cacheNode.get(i), nd);
						}
						tag++;
						break;
					}
				}
			}
			
			if (tag == 0) {
				return ErrorCode.ERR_PARENT_CONTAIN_NODES_ERROR;
			}
			
			if (tag == nodesName.size()) {
				return ErrorCode.SUCCESS;
			} else {
				return ErrorCode.ERR_PARENT_CONTAIN_NODES_ERROR;
			}
		} catch (MstpException e) {
			e.printStackTrace();
			return e.getErrorCode();
		}
	}
}
